﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.HtmlControls;

namespace Bookkeeping.Web.UserControls
{
    public class CssHelper
    {
        public const string PositiveAmountClass = "positive";
        public const string NegativeAmountClass = "negative";

        public static void AdjustClassForAmount(HtmlGenericControl control, double amount)
        {
            string cssClass = GetClassForAmount(amount);

            SetOrAppendClass(control, cssClass);
        }

        private static void SetOrAppendClass(HtmlGenericControl control, string cssClass)
        {
            if (string.IsNullOrEmpty(control.Attributes["class"]))
                SetClass(control, cssClass);
            else
                AppendClass(control, cssClass);
        }

        private static void AppendClass(HtmlGenericControl control, string cssClass)
        {
            control.Attributes["class"] += " " + cssClass;
        }

        private static void SetClass(HtmlGenericControl control, string cssClass)
        {
            control.Attributes["class"] = cssClass;
        }

        private static string GetClassForAmount(double amount)
        {
            if (amount < 0)
                return NegativeAmountClass;

            return PositiveAmountClass;
        }
    }
}
